using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using System.IO;
using System.Diagnostics;
using System.Threading;
using LLG.SharePoint.Services;

namespace LLG.SharePoint.ServicesTests
{
    [TestFixture]
    public class SPWebServiceDeployerTests
    {
        private string siteUrl;
        private DirectoryInfo _hive12;

        [SetUp]
        public void Setup()
        {
            //ensure all files are prepared for the tests.
            DirectoryInfo _templatesDir = new DirectoryInfo("..\\..\\_templates");
            _hive12 = new DirectoryInfo("..\\..\\12");
            DirectoryInfo _layouts = _hive12.GetDirectories("TEMPLATE")[0].GetDirectories("LAYOUTS")[0];
            DirectoryInfo _isapi = _hive12.GetDirectories("ISAPI")[0];
            DirectoryInfo _featureDir = _hive12.GetDirectories("TEMPLATE")[0].GetDirectories("FEATURES")[0].GetDirectories("WebServicesDeploymentFeature")[0];

            File.WriteAllText(_layouts.FullName + "\\Web.config", File.ReadAllText(_templatesDir.FullName + "\\Web.config")); //we're mocking the virtual service here.
            File.WriteAllText(_isapi.FullName + "\\spdisco.aspx", File.ReadAllText(_templatesDir.FullName + "\\spdisco.aspx"));

            siteUrl = "http://localhost:969";
        }
        [Test]
        public void createDiscoAndWsdl()
        {
            SPWebServiceDeployer spd = new SPWebServiceDeployer(siteUrl, "WebServicesDeploymentFeature", _hive12.FullName);
            spd.GenWebService();
            Assert.AreEqual(4, spd.hive12.GetDirectories("ISAPI")[0].GetFiles().Length, "expecting 4 files: *.asmx, *disco.aspx, *wsdl.aspx, spdisco.aspx");
        }
        [Test]
        public void genThenDestroy()
        {
            SPWebServiceDeployer spd = new SPWebServiceDeployer(siteUrl, "WebServicesDeploymentFeature", _hive12.FullName);
            //let's see if we can kill it too. 
            spd.RemoveAllWebServices();
            Assert.AreEqual(1, spd.hive12.GetDirectories("ISAPI")[0].GetFiles().Length);
        }
        [TearDown]
        public void TearDown()
        {
            
        }
    }
}
